package ru.amse.tsyganov.jumleditor.model;

import java.util.HashSet;
import java.util.Set;


public class StateVertex {
	private final Set<Transition> outgoing = 
		new HashSet<Transition>();
	
	private final Set<Transition> incoming = 
		new HashSet<Transition>();
	
	private final State container;
	
	public StateVertex(State container) {
		if (container == null) {
			throw new IllegalArgumentException();
		}
		this.container = container;
	}
	
	public boolean addOutgoingTransition(Transition t) {
		boolean result = outgoing.add(t);
		if (result && container.getActivityGraph() != null) {
			container.getActivityGraph().fireModelChanged();
		}
		return result;
	}
	
	public boolean removeOutgoingTransition(Transition t) {
		boolean result = outgoing.remove(t);
		if (result && container.getActivityGraph() != null) {
			container.getActivityGraph().fireModelChanged();
		}
		return result;
	}
	
	public boolean containsOutgoingTransition(Transition t) {
		return outgoing.contains(t);
	}
	
	public int outgoingTransitionsSize() {
		return outgoing.size();
	}
	
	public boolean addIncomingTransition(Transition t) {
		boolean result = incoming.add(t);
		if (result && container.getActivityGraph() != null) {
			container.getActivityGraph().fireModelChanged();
		}
		return result;
	}
	
	public boolean removeIncomingTransition(Transition t) {
		boolean result = incoming.remove(t);
		if (result && container.getActivityGraph() != null) {
			container.getActivityGraph().fireModelChanged();
		}
		return result;
	}
	
	public boolean containsIncomingTransition(Transition t) {
		return incoming.contains(t);
	}
	
	public int incomingTransitionsSize() {
		return incoming.size();
	}
	
	public Iterable<Transition> getOutgoing() {
		return outgoing;
	}


	public Iterable<Transition> getIncoming() {
		return incoming;
	}


	public State getContainer() {
		return container;
	}
}
